﻿using System;
using System.Net;
using System.Text;
using DGM.Objects.Media.Imbd;
using Newtonsoft.Json;

namespace DGM.Util.Helpers.MediaRatingApis.Imdb
{
  /**
i	          string (optional)	 a valid IMDb movie id
t	          string (optional)	 title of a movie to search for
y	          year (optional)	 year of the movie
r	          JSON, XML	 response data type (JSON default)
plot	      short, full	 short or extended plot (short default)
callback	  name (optional)	 JSONP callback name
tomatoes	  true (optional)	 adds rotten tomatoes data
   */

  public static class DImdbApiHelper
  {
    public static ImbdApiJson GetMovieInfoByTitle(string title)
    {
      ImbdApiJson result = null;

      string url = string.Format("http://www.imdbapi.com/?t={0}", title);
      using(var webClient = new WebClient())
      {
        webClient.Encoding = Encoding.UTF8;
        string webstreamResult = webClient.DownloadString(url);

        result = JsonConvert.DeserializeObject<ImbdApiJson>(webstreamResult);
      }

      return result;
    }
  }
}
